package cn.tedu.mall.seckill.controller;

import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.seckill.vo.SeckillSkuVO;
import cn.tedu.mall.seckill.service.ISeckillSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SeckillSkuController {
    @Autowired
    private ISeckillSkuService seckillSkuService;

    /**
     * 在redis中通过spuId查询sku列表
     */
    @GetMapping("/seckill/sku/list/{spuId}")
    @PreAuthorize("permitAll()")
    public JsonResult<List<SeckillSkuVO>> getSkusBySpuId(
            @PathVariable("spuId") Long spuId) {
        List<SeckillSkuVO> seckillSkuVOS = seckillSkuService.listSeckillSkus(spuId);
        return JsonResult.ok(seckillSkuVOS);
    }
}
